<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java并发编程核心概念</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 20px;
            overflow-x: auto;
            position: relative;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 15px;
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
            box-shadow: 0 10px 30px rgba(240, 147, 251, 0.3);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        pre code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        
        .thread-state-card {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .thread-state-card:hover {
            border-color: #667eea;
            transform: translateY(-3px);
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.2);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">Java并发编程核心概念</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl">深入理解进程、线程与并发机制，掌握现代Java多线程编程的精髓</p>
            <div class="mt-8 flex items-center space-x-6">
                <div class="flex items-center">
                    <i class="fas fa-microchip mr-2"></i>
                    <span>多核优化</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-sync-alt mr-2"></i>
                    <span>并发控制</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>线程安全</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        
        <!-- 进程和线程概念 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-server mr-3 text-purple-600"></i>进程和线程
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                    <div class="feature-icon">
                        <i class="fas fa-desktop"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">进程 (Process)</h3>
                    <p class="text-gray-600 leading-relaxed">
                        <span class="drop-cap">进</span>程是在内存中运行的应用程序。每个进程都有自己独立的一块内存空间，一个进程就是一个xxx.exe。进程是操作系统资源分配的基本单位。
                    </p>
                </div>
                
                <div class="bg-gradient-to-br from-blue-50 to-indigo-50 p-6 rounded-xl">
                    <div class="feature-icon" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                        <i class="fas fa-stream"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">线程 (Thread)</h3>
                    <p class="text-gray-600 leading-relaxed">
                        <span class="drop-cap">线</span>程是进程中的一个执行任务（控制单元），负责当前进程中程序的执行。一个进程可以运行多个线程，多个线程可共享数据。
                    </p>
                </div>
            </div>

            <!-- 进程与线程的区别 -->
            <div class="mt-10">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">
                    <i class="fas fa-exchange-alt mr-2 text-purple-600"></i>进程与线程的区别
                </h3>
                
                <div class="space-y-4">
                    <div class="thread-state-card">
                        <h4 class="font-semibold text-purple-700 mb-2">
                            <i class="fas fa-cube mr-2"></i>根本区别
                        </h4>
                        <p class="text-gray-600">进程是操作系统资源分配的基本单位，而线程是处理器任务调度和执行的基本单位</p>
                    </div>
                    
                    <div class="thread-state-card">
                        <h4 class="font-semibold text-blue-700 mb-2">
                            <i class="fas fa-coins mr-2"></i>资源开销
                        </h4>
                        <p class="text-gray-600">每个进程都有独立的代码和数据空间，程序之间的切换会有较大的开销；每个线程都有自己独立的运行栈和程序计数器（PC），线程之间切换的开销小。</p>
                    </div>
                    
                    <div class="thread-state-card">
                        <h4 class="font-semibold text-green-700 mb-2">
                            <i class="fas fa-sitemap mr-2"></i>包含关系
                        </h4>
                        <p class="text-gray-600">如果一个进程内有多个线程，则执行过程不是一条线的，而是多条线（线程）共同完成的；线程是进程的一部分。</p>
                    </div>
                    
                    <div class="thread-state-card">
                        <h4 class="font-semibold text-orange-700 mb-2">
                            <i class="fas fa-memory mr-2"></i>内存分配
                        </h4>
                        <p class="text-gray-600">同一进程的线程共享本进程的地址空间和资源，而进程之间的地址空间和资源是相互独立的</p>
                    </div>
                    
                    <div class="thread-state-card">
                        <h4 class="font-semibold text-pink-700 mb-2">
                            <i class="fas fa-play-circle mr-2"></i>执行过程
                        </h4>
                        <p class="text-gray-600">每个独立的进程有程序运行的入口、顺序执行。但是线程不能独立执行，必须依存在应用程序中。</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Java内存模型 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                <i class="fas fa-microchip mr-3 text-purple-600"></i>Java内存模型
            </h3>
            <div class="bg-gray-100 rounded-xl p-6 text-center">
                <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1651632977821-81ef3959-9600-433c-a410-b6e5e8395e01.png" 
                     alt="Java内存模型" 
                     class="mx-auto rounded-lg shadow-lg"
                     style="max-width: 100%; height: auto;">
            </div>
        </div>

        <!-- 并发和并行 -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sync-alt mr-3 text-purple-600"></i>并发和并行
            </h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="highlight-box">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-clock mr-2"></i>并发 (Concurrency)
                    </h3>
                    <p class="leading-relaxed">单核CPU，多个线程操作同一个资源，在一个CPU上跑多个线程，通过快速交替的方式，达到一种并行的假象。</p>
                </div>
                
                <div class="highlight-box" style="background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-layer-group mr-2"></i>并行 (Parallelism)
                    </h3>
                    <p class="leading-relaxed">多核CPU，多个线程同时执行，在每个CPU上同时都有一个线程在运行。</p>
                </div>
            </div>

            <!-- 可视化图表 -->
            <div class="mt-8">
                <div class="mermaid">
                    graph LR
                    A[单核CPU] --> B[线程1]
                    A --> C[线程2]
                    A --> D[线程3]
                    B -.->|时间片轮转| C
                    C -.->|时间片轮转| D
                    D -.->|时间片轮转| B
                    
                    E[多核CPU] --> F[核心1-线程1]
                    E --> G[核心2-线程2]
                    E --> H[核心3-线程3]
                    
                    style A fill:#f093fb,stroke:#333,stroke-width:2px
                    style E fill:#4facfe,stroke:#333,stroke-width: